home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hardcore Visual Basic 5.0 (2nd Edition)
/
Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso
/
Code
/
README.TXT
< prev
next >
Wrap
Text File
|
1997-12-11
|
12KB
|
240 lines
Hardcore Visual Basic, Second Edition
Copyright 1997, Microsoft Press
The CD contains the sample programs for the book Hardcore Visual
Basic. Since the legalese on the license agreement page is a little
hard to interpret, let me clarify your rights to use the code.
Copyright law protects written publication--in other words, your right
to republish printed source code. The terms are spelled out in the
license agreement. But you're probably not interested in publishing
the source; you just want to use the code in your programs. That's
what it's for. If you paid for it, it's yours. Microsoft does not
claim ownership of the algorithms.
Sample Programs
---------------
You can examine sample programs in three ways. Let's say you want to
start with the Fun 'n Games program from Chapter 7. This program
illustrates graphics techniques. You can start by running FUNNGAME.EXE
to see what it does. The setup program copies the sample programs to
the Exes directory on your hard disk.
Sample EXE programs will work from your local disk if you ran the
setup program or registered the components using the batch files
described later. FUNNGAME.EXE uses four of the components described in
the book. The VBCore.DLL component provides miscellaneous services.
VisualCore.DLL provides forms wrapped in public classes--Fun 'N Games
uses CColorPicker and COpenPictureFile. SubTimer.DLL is a small
component that provides timer and subclassing services--Fun 'n Games
uses CTimer. Finally, the program uses the XPictureGlass control from
PictureGlass.OCX.
After you've clicked on a few buttons and been amazed by swirling
cars, a spiraling ball, and shuffled cards, you'll probably want to
see what makes these tricks work. The next step is to go to the
directory created by the setup program (Hardcore2 by default) and load
the project FUNNGAME.VBP into the Visual Basic IDE. You can step
through the program and examine any of its code as an example of how
to call the same components from your own programs.
You can stop right there if you want, but most hardcore programmers
will probably want to take the next step and look inside the
components. You can't do that from the VBP file because it references
the compiled components. So you load the project group FUNNGAME.VBG.
This one includes VBCore.VBP, VisualCore.VBP, and PictureGlass.VBP
(but not SubTimer.VBP). You can step from the program into the more
than 80 classes and modules of VBCore, or check out the five lines of
new code I wrote to create the XPictureGlass control.
If you're really hardcore and want to see the whole thing, you can
load FUNNGAMEDEB.VBG, which adds SubTimer.VBP to the mix. FUNNGAME.VBG
references the compiled SubTimer.DLL and not the project because, as
Chapter 6 explains, it's notoriously difficult to debug subclassing or
timer code that uses callbacks. That's why the code is in the SubTimer
component rather than in VBCore.
You might not have noticed in your haste to get your hands on the
code, but the package around the CD is actually a free book. It won't
compile or run, but you can read it in bed. Check out Chapter 5 where
the project layout is explained in more detail.
Directory Layout
----------------
The directory installed by setup looks like this:
Hardcore2 Sample project and source files, README
Compare Compatibility files for components
Debug Debug versions of components
Exes Executable sample programs
Goodies Extra tools from readers of the first edition
LocalModules Private versions of classes and standard modules
Release Release versions of components
Tools RegSvr32.EXE
Chapter 5 describes the differences between Debug and Release versions
of components.
Setup Notes
-----------
Setup is very simple. It simply copies the most important files from
the CD to a directory you specify (default Hardcore2). It then
registers components and type libraries.
You can undo the work done by the setup program by uninstalling with
the Add/Remove Programs applet from the Control Panel. You can also do
the same operations by hand. To uninstall the components, run the
UNREGISTERALL.BAT file. There are also batch files to register either
debug or release versions of the components--TODEBUG.BAT and
TORELEASE.BAT.
Unfortunately, I have no utility to unregister type libraries. You can
unregister the ANSI and Unicode versions of the Windows API type
library by removing keys 64674040 and 64675040 from the TypeLib key
under HKEY_CLASSES_ROOT in the system registry.
After unregistering all tools, you can delete any directories you
don't want.
Setup copies CARDS32.DLL (used in the Fun 'n Games program) to your
Windows directory. You can delete this DLL if you have no interest in
programming card games.
If you run setup under Microsoft Windows NT, it copies PSAPI.DLL to
your system directory. This DLL is required for iterating through
processes and modules. It is described in Chapter 6. The WinWatch
utility uses it under Windows NT only. If you have a dual-boot system
and install under Microsoft Windows 95, the setup will not copy
PSAPI.DLL to your Windows NT system directory (because it doesn't know
where the directory is). In this case, you must copy PSAPI.DLL by
hand.
Goodies
-------
Readers of the first edition of my book answered some of my
challenges, and some of their own. The Goodies directory has some
interesting code and components. Some are source code samples. Others
are licensed controls. I'm giving these out as a courtesy, but the
authors (who are listed in README files in each directory) are
responsible. Setup installs the directories, but you'll need to
manually run setup programs for some of them. If you decide to remove
a tool, make sure you unregister it before deleting the files so that
you don't leave orphaned entries in the registry.
The programs in the Goodies directory are the ones available at the
time the book was published. The Hardcore Hackers' Hall of Fame on my
web site may have more goodies and later versions of some of the the
originals. You can see the latest at:
www.pobox.com/HardcoreVB/hackhall.htm.
The Source directory on the CD contains some C++ articles I wrote for
the Microsoft Developer Network CD and for Visual Basic Programmer's
Journal. Although the components and DLLs described in them are for
Visual Basic, they're written in C++. I didn't think these would be of
general interest to readers of the book, so the setup program doesn't
copy them to your disk. The source for the Windows API type library is
also in this directory.
Bugs! What bugs?
---------------
There are a few differences between the code on the CD and the code in
the book. Fortunately, many of these are improvements rather than
fixed bugs:
- The BytesToStr function on page 279 is incorrect. The correct code
is shown below:
Function BytesToStr(ab() As Byte) As String
BytesToStr = StrConv(ab, vbUnicode)
End Function
This code is correct on the CD.
- The code examples on pages 249-251 illustrate the error scheme used
throughout my components. It uses one of the largest modules,
Utility.Cls, but this module changed after the chapter was finished.
A new error was added to the EErrorUtility Enum, VBCore's resource
table, and the local ErrRaise procedure.
- The description on page 353 states that my subclassing mechanism
expects one message per class (middle of the page). Fortunately,
this statement is false, as the CPalette class in VBCore proves. A
class that implements ISubclass can handle as many messages as it
wants as long as it attaches each of them with AttachMessage and
handles them in the ISubclass_WindowProc method. In other words,
the subclassing mechanism is even more flexible than I thought when
I wrote the code. The second limitation described in the same
paragraph--that you couldn't write several different classes to
handle the same message--is true.
- The AnimateBacks procedure shown on pages 426 and 427 had a bug. An
early exit through a conditional Exit Sub failed to restore the
ScaleMode saved at the beginning of the procedure. The results of
drawing in twips mode when the machine is still in pixel mode
aren't pretty. The code is correct on the CD.
- The "Palette tricks" section on page 461 was purposely vague
because when I wrote it I didn't really know how to manage palettes
in Visual Basic. Now I do--at least partly. The CPalette class and
the TPalette program were finished in the wee hours of the morning
before we shipped. What I wrote for the book wasn't too bad, but
subclassing is mandatory, not optional, and the AutoRedraw setting
mentioned in the text doesn't really have much to do with anything.
The comments in the source for the CPalette class and the TPalette
program explain palettes in more detail.
- The Add method of the XListBoxPlus control has an extra optional
parameter that isn't shown in the listing on page 619. The new
parameter is an ItemData member that allows you to add string items
and numeric item data with one statement. Instead of this:
lst.AddItem "WindowText"
lst.ItemData(lst.NewIndex) = hWnd
Do this:
list.Add "WindowTest", , hWnd
The same listing also fails to call the PropertyChanged method to
let the property page know the List property has changed. This
omission is fixed on the CD.
- The performance sidebar on page 671 has the wrong timings in the
p-code column. It might be nice if p-code were the same speed as
native code, but the correct numbers are:
Problem Native code P-code
------- ----------- ----------
Find files with Basic Dir$ 39 seconds 49 seconds
Find files with FindFirstFile API 9 seconds 13 seconds
User the Windows Explorer Find dialog 6 seconds 6 seconds
- I'm sorry to say that the Meriwether Explorer application described
on pages 680 and 681 isn't much better than the pitiful Columbus
application provided with the first edition. In fact, this version
does even less, although it has more potential. I got the program
working just in time to get a screen dump for the book, but I
planned to spend more time polishing it before the CD shipped.
Well, other things came up, and I didn't work with Meriwether
much more. Fortunately, this version is based on a more flexible
architecture. Unlike Columbus, it shows the whole namespace and
does so at an acceptable speed. You should be able to enhance it
into a usable replacement for Windows Explorer.
I'm sure there are other problems that I haven't discovered yet. I did
my best to write bug-free code, but when I had a choice between adding
interesting features or testing existing code, I added the new
features. These samples are not as bullet-proof as I would have made
them had I been shipping programs without source. I apologize for any
bugs. Please send any bug fixes or enhancements to brucem@pobox.com. I
will fix and distribute them on my web site.
Bruce McKinney
www.pobox.com/HardcoreVB